﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BlueCMS.Core.Data.Query.Clauses;

namespace BlueCMS.Core.Data.Query
{
    public class UnionQuery
    {
        UnionClause UnionClause { get; set; }
        OrderByClause OrderByClause { get; set; }

        public UnionQuery()
        {
            UnionClause = new UnionClause();
            OrderByClause = new OrderByClause();
        }

        public UnionQuery(SelectQuery query) 
        {
            UnionClause.Query(query);
        }

        public UnionQuery(SelectQuery query1, SelectQuery query2)
        {
            UnionClause.Query(query1);
            UnionClause.Query(query2);
        }

        public IUnionClause Union
        {
            get { return UnionClause; }
        }

        public IOrderByClause OrderBy
        {
            get { return OrderByClause; }
        }

        public string Sql
        {
            get
            {
                return DataAccess.Instance.GetQueryGenerator().ProcessUnionQuery(UnionClause, OrderByClause);
            }
        }

        public override string ToString()
        {
            return Sql;
        }
    }
}
